<?php

class PhotoDAO extends BaseDAO{

    public function getAll(){
        $list ;
        $sql='SELECT * FROM `photo` LIMIT 0,25 ;';
        $result = mysql_query($sql);
        while($row = mysql_fetch_object($result,'photo')) {
            $list[] = $row;
        }
        return $list;
    }


    public function getByGalleryId($id){
        $sql='SELECT * FROM `photo` WHERE `gallery_id`= '.$id.';';
        $result = mysql_query($sql);
        while($row = mysql_fetch_object($result,'photo')) {
            $list[] = $row;
        }
        return $list;
    }


    public function getById($id){
        $sql='SELECT * FROM `photo` WHERE `photo`.`id`= '.$id.';';
        $result = mysql_query($sql);
        return mysql_fetch_object($result,'photo');
    }

    public function insert($photo){
        $id=  false;
        $sql='INSERT INTO `photo` (
        `gallery_id`,
        `original`,
        `mini`,
        `midi`,
        `maxi`,
        `title`,
        `description`,
        `created`) VALUES(
        '.$photo->gallery_id.',
        \''.$photo->original.'\',
        \''.$photo->mini.'\' ,
        \''.$photo->midi.'\',
        \''.$photo->maxi.'\',
        \''.$photo->title.'\',
        \''.$photo->description.'\',
        NOW());';
        $result = mysql_query($sql);
        if($result){
            $id = mysql_insert_id();
        }
        return $id;
    }

    public function update($photo){
        $sql='UPDATE `photo` SET
        `title`=\''.$photo->title.'\',
        `description`=\''.$photo->description.'\' WHERE `id`=\''.$photo->id.'\' ;';
        $result = mysql_query($sql);
    }


    public function delete($id){
        $sql='DELETE FROM `photo` WHERE `id`='.$id.';';
        $result = mysql_query($sql);
    }


    public function PhotoDAO(){
        $this->initDB();
    }

}
?>
